﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace CXW.Core.Sharp.Commands
{
    class TestCommand : AbstractMenuCommand
    {
        public override void Run()
        {
            MessageService.ShowMessage(string.Format("Test : CodonId = {0}, CfgName = {1}, Label = {2}, Args = {3}", CodonId, CfgName, Label, Args));
        }
    }
    /// <summary>关于窗口</summary>
    class AboutCommand : AbstractMenuCommand
    {
        public override void Run()
        {
            (new AboutBox()).ShowDialog();
        }
    }
    /// <summary>打开计算器</summary>
    class CalculatorOpenCommand : AbstractCommand
    {
        public const int SW_NORMAL = 1;
        public const int SW_RESTORE = 9;
        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        public override void Run()
        {
            Process[] procArray = Process.GetProcessesByName("calc");
            if (procArray.Length == 0)
            {
                Process procCalculator = new Process();
                procCalculator.StartInfo.FileName = "calc";
                procCalculator.Start();
            }
            else
            {
                ShowWindow(procArray[0].MainWindowHandle, SW_NORMAL);
                SetForegroundWindow(procArray[0].MainWindowHandle);
            }
        }
    }
    /// <summary>退出功能</summary>
    class ExitWorkbenchCommand : AbstractCommand
    {
        public override void Run()
        {
            WorkbenchSingleton.Workbench.Close();
        }
    }
    /// <summary>重启功能</summary>
    class RestartWorkbenchCommand : AbstractCommand
    {
        public override void Run()
        {
            if (MessageService.AskQuestion(ResourceService.GetString("Info.RestartConfirm"), "Info.CaptionWarning"))
            {
                WorkbenchSingleton.Workbench.ConfirmExit = false;
                System.Windows.Forms.Application.Restart();
            }
        }
    }
    /// <summary>切换状态栏是否显示</summary>
    class StatusCommand : AbstractCommand
    {
        public override void Run()
        {
            WorkbenchSingleton.Workbench.SetStatusBar();
        }
    }
    /// <summary>切换语言</summary>
    class SwitchUiLanguageCommand : AbstractCommand
    {
        public override void Run()
        {
            new UILanguageForm().ShowDialog();
        }
    }
    /// <summary>皮肤切换</summary>
    class SkinChangeCommand : AbstractMenuCommand
    {
        public override void Run()
        {
            WorkbenchSingleton.Workbench.SetLookAndFeel(CodonId);
        }
    }
}
